package com.patttern.creativity.clone;

import java.io.Serializable;

/**
 * @Author: root
 * @Date: 2018/12/3 21:46
 */
public class Person implements Serializable, Cloneable {
    private String name;
    private int age;
    private Address address;

    public Person() {
    }

    public Person(String name, int age, Address address) {
        this.name = name;
        this.age = age;
        this.address = address;
    }

    public String  getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person person = (Person) super.clone();
        Address address = (Address) person.getAddress().clone();
        person.setAddress(address);
        return person;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name=" + name +
                ", age=" + age +
                ", address=" + address +
                '}';
    }
}
